#-*-coding:utf-8-*-#
import sys


if len(sys.argv) != 2:
    print("python input.py nnie-result.txt")
    sys.exit()

print ('creating detection-results/*.txt')

classnums = 'test wajue tuituji wajue_head people cache'
with open(sys.argv[1]) as f:
    while 1:
        lines = f.readlines(10000)
        if not lines:
            break
        for line in lines:
            # print(line.split())
            name = line.split(' ')[0].split('/')[2].split('.')[0]
            ddata = line.split(' ', 1)[1]
            sdata = ddata.split()
            size = 6

            with open('./data/'+name+'.dat') as ff:
                scal_data = ff.readline()
                width, heigth = scal_data.split()
                w = int(width)
                print(w/608)

                width_scal = int(width)/608
                hight_scal = int(heigth)/608
            print('{} {} {} {} {} {} '.format(width,
                                              heigth, width_scal, hight_scal, 4032/608, 2268/608))
            with open('./detection-results/'+name+".txt", 'w') as ff:
                for i in range(0, int(len(sdata)) + 1, size):
                    c = sdata[i:i+size]
                    if c != []:
                        ff.write("{} {} {} {} {} {}\n".format(classnums.split(' ')[(int(c[0]))],
                                                            float(c[5]), int(
                                                                int(c[1]) * width_scal), int(int(c[2]) * hight_scal),
                                                            int(int(c[3]) * width_scal), int(int(c[4]) * hight_scal)))
            ff.close()
f.close()
